<%@page import="model.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
	String eid="";
	String n = null;
	String m =null;
	String t = null;
	String en=null;
	String em= null;
	String et =null;
	User u =new User();
	Message message= new Message();
	/* get info where error */
	String mid = (String) request.getParameter("mid");
	if(!message.isMID(mid)){
		response.sendRedirect("message.jsp?m=err-mid&r=vm"); 
	}else{
	message = message.getMg(Integer.parseInt(mid));	
	n = ((String)request.getAttribute("n"));
	m = (String) request.getAttribute("m");
	t = ((String)request.getAttribute("t"));
	et = (String) request.getAttribute("et");
	en = ((String)request.getAttribute("en"));
	em = (String) request.getAttribute("em");
	n = (n==null)? message.getM_name():n ;
	m = (m==null)?message.getM_content():m ;
	t = (t==null)? message.getM_title():t ;
	et = (et==null)? "*":et ;
	en = (en==null)? "*":en ;
	em = (em==null)? "*":em ;
	}
	//kiem tra có phải admin không nếu khong thi redirect home
	if (!u.isAdmin((String) session.getAttribute("lv"))) {
		response.sendRedirect("../index.jsp");
	}
%>
<title>MYFILM - Message</title>
		<form action="EditMessage" onsubmit="return validate(this)" method="post">
			<fieldset>
				<legend>Edit Message: <%=(message.getM_name()==null)?"":message.getM_name() %></legend>
				<div>
					<label for="n">Message Name: <span class="required"><%=en %></span></label>
					<input type="text" name="n" id="von" value="<%=n %>" size="20" maxlength="150" tabindex="1"/>
				</div>
				<div>
					<label for="n">Message Title: <span class="required"> <%=et%></span></label>
					<input type="text" name="t" id="von" value="<%=t%>" size="20" maxlength="150" tabindex="1"/>
				</div>
				<div>
					<label for="m">Message: <span class="required"><%=em %></span></label> 
					<textarea name="m" rows="3" cols="50" ><%=m %></textarea>
				</div>
				<input type="hidden" name="uid" value="<%=session.getAttribute("lv")%>">
				<input type="hidden" name="mid" value="<%=message.getMid()%>">
			</fieldset>
			<p>
				<input type="submit" name="submit" value="Apply" />
			</p>
		</form>